﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using Cinch;
using MEFedMVVM.ViewModelLocator;
using SLS.Controls;
using SLS.Document;
using SLS.ExClassLib.Data;
using SLS.ExClassLib.Events;
using SLS.ExClassLib.MVVM;
namespace SLS.Presentation
{
    /// <summary>
    /// This ViewModel demonstrates how to use WorkSpaces and Menus. You will
    /// need to look in the MainWindow.xaml and also the AppStyles.xaml ResourceDictionary
    /// to see how the Styles are used to tie up with this ViewModel
    /// </summary>
    [ExportViewModel("GTKRViewModel")]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class GTKRViewModel : ViewModelBase
    {
        #region Data
        private bool showContextMenu = false;
        private IViewAwareStatus viewAwareStatusService;
        private IMessageBoxService messageBoxService;
        private IMenuService menuservice;
        #endregion
        #region Ctor
        [ImportingConstructor]
        public GTKRViewModel(
        IViewAwareStatus viewAwareStatusService,
        IMessageBoxService messageBoxService,
        IMenuService menuservice)
        {
            BaseTable = "GTKR";
            this.viewAwareStatusService = viewAwareStatusService;
            this.viewAwareStatusService.ViewLoaded += ViewAwareStatusService_ViewLoaded;
            this.messageBoxService = messageBoxService;
            this.menuservice = menuservice;
        }
        #endregion

        #region Private Methods
        public override void ActiveExDataRow_Changed(ExDataRow dwThis)
        {
            if (dwThis.TBName != BaseTable)
                return;
            base.ActiveExDataRow_Changed(dwThis);
            try
            {
                BuildEnvDataSet(dwThis);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void ViewAwareStatusService_ViewLoaded()
        {

            #region==============ViewDataSet================================
            IDataModel contextViewDataSEt = ViewDataSet;
            ViewDataSet = new DataModel("CustomerMaster");
            #endregion

            #region==============LoadAssembly================================
            ArrayList assemblylist = new ArrayList();
            DocumentManagement.Instance.LoadAssembly(assemblylist);

            #endregion
            #region==============Documents================================
            string doctype = "";
            WorkspaceData wks = null;

            doctype = "DetailGTKRQueryCond";
            wks = new WorkspaceData("", doctype, null, "QueryCond", true);
            Documents.Add(wks);
            SetActiveWorkspace(wks);
            doctype = "GridTableGTKR";
            wks = new WorkspaceData("", doctype, null, "Result", true);
            Documents.Add(wks);
            doctype = "DetailGTKR";
            wks = new WorkspaceData("", doctype, null, "Detail", true);
            Documents.Add(wks);

            #endregion
            #region==============DocumentsData================================
            doctype = "DATAGTKR";
            wks = new WorkspaceData("", doctype, null, "GTKR", true);

            DocumentsData.Add(wks);

            #endregion
            #region==============DocumentsKey================================
            #endregion
            #region==============WorkFlow================================
            doctype = "EditGTKR";
            DocumentManagement.Instance.OpenDocument(doctype, "WFEditDocuments");
            #endregion
            #region==============DocumentsCore================================
            doctype = "DATAGoodsMasterKeyRelation";
            wks = new WorkspaceData("", doctype, null, "GoodsMasterKeyRelation", true);
            DocumentsCore.Add(wks);
            doctype = "DATAGoodsMasterAssemblePoint";
            wks = new WorkspaceData("", doctype, null, "GoodsMasterAssemblePoint", true);
            DocumentsCore.Add(wks);
            doctype = "DATAGoodsMasterProperty";
            wks = new WorkspaceData("", doctype, null, "GoodsMasterProperty", true);
            DocumentsCore.Add(wks);
            #endregion
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Returns the bindbable MenuOptions
        /// </summary>
        public List<WPFMenuItem> M10006401
        {
            get
            {
                return menuservice.GetChildMenu("10006401");
            }
        }



        /// <summary>
        /// ShowContextMenu
        /// </summary>
        static PropertyChangedEventArgs showContextMenuArgs =
            ObservableHelper.CreateArgs<GTKRViewModel>(x => x.ShowContextMenu);

        public bool ShowContextMenu
        {
            get { return showContextMenu; }
            private set
            {
                showContextMenu = value;
                NotifyPropertyChanged(showContextMenuArgs);
            }
        }
        #endregion
    }
}

